<script type="text/javascript" >
    var listingType = '<?php echo $this->listingType ?>';
    var listingId = '<?php echo $this->listingId ?>';
    var country_id = <?php echo $this->subject->getIdentity()?>;
    var notChangeLink = ['manage','categories'];
    String.prototype.ReplaceAll = function(stringToFind,stringToReplace){
        var temp = this;
        var index = temp.indexOf(stringToFind);
        while(index != -1){
            temp = temp.replace(stringToFind,stringToReplace);
            index = temp.indexOf(stringToFind);
        }
        return temp;
    };
    
    var url = en4.core.baseUrl;
   
    function addCountryIdToPostNew(){
        var a = $$('.layout_country_content .tip a');
        var url = a.get('href');
        url = url+'/cid/'+country_id;
        a.set('href',url);
    }
    function removeFormLink(){
        $$('.field_search_criteria').set('action','');
    }
    function changeLinkMenu(){
        var container = $('nav_cat_');
        var els = container.getElements('a');
        for (var j = 0; j < els.length; j ++){
            var el = $(els[j]);
            var href = el.get('href');
            if (href.contains('/countries/view/')) continue;
            if (href[0] == '/'){
                href = href.substring(1);
            } 
            href = href.ReplaceAll('/','-');
            if (location.pathname.contains('/countries/view/')  ){
                 var exp = new RegExp('/countries/view/id/\\d*');
                 var curl = exp.exec(location.pathname)
                 el.set('href',curl+'/pr/'+href);
            }
                
        }
    }
    function changeLinkBrowseView(){
        var links = $$('.sr_category.clr');
        for( var i = 0; i < links.length; i++){
            var link = links[i].getElement('a');
            var href = link.get('href');
            if (href == null ) continue;
            if (!href.contains('/countries/view/')) {
                if (href[0] == '/'){
                    href = href.substring(1);
                }
                href = href.ReplaceAll('/','-');
                if (location.pathname.contains('/countries/view/') ){
                     var exp = new RegExp('/countries/view/id/\\d*');
                     var curl = exp.exec(location.pathname)
                     link.set('href',curl+'/pr/'+href);
                }
            }
        }
        var browse = $$('.sr_browse_list_info');
        if (browse.length > 0 ){
            for (var i = 0; i < browse.length; i++){
                var categories = browse[i].getElements('div.sr_browse_list_info_stat');
                    for (var cc = 0; cc < categories.length; cc++){
                    var c = categories[cc].getChildren();
                        if (c.length < 1 ) continue;
                        if (c[0].get('tag') == 'a'){
                            var href = c[0].get('href');
                            if (!href.contains('/countries/view/')) {
                                if (href[0] == '/'){
                                    href = href.substring(1);
                                }
                                href = href.ReplaceAll('/','-');
                                if (location.pathname.contains('/countries/view/') ){
                                     var exp = new RegExp('/countries/view/id/\\d*');
                                     var curl = exp.exec(location.pathname)
                                     c.set('href',curl+'/pr/'+href);
                                }
                            }
                        }
                        
                    
                }    
            }
        }
    }
    function changeLinkNavigate(){
        var home = $$('.sitereview_main_home_listtype_'+listingId);
        if (home.length > 0) {
            var el = $(home[0]);
            var href = el.get('href');
            if (!href.contains('/countries/view/')){
                if (href[0] == '/'){
                    href = href.substring(1);
                } 
                href = href.ReplaceAll('/','-');
                if (location.pathname.contains('/countries/view/') ){
                     var exp = new RegExp('/countries/view/id/\\d*');
                     var curl = exp.exec(location.pathname)
                     el.set('href',curl+'/pr/'+href);
                }
            }
        }
        home = $$('.sitereview_main_browse_listtype_'+listingId);
        if (home.length > 0){
            el = $(home[0]);
            href = el.get('href');
            if (!href.contains('/countries/view/')){
                if (href[0] == '/'){
                    href = href.substring(1);
                } 
                href = href.ReplaceAll('/','-');
                if (location.pathname.contains('/countries/view/') ){
                     var exp = new RegExp('/countries/view/id/\\d*');
                     var curl = exp.exec(location.pathname)
                     el.set('href',curl+'/pr/'+href);
                }
            }
        }
        home = $$('.sitereview_main_manage_listtype_'+listingId);
        if (home.length > 0){
            el = $(home[0]);
            href = el.get('href');
            if (!href.contains('/countries/view/')){
                if (href[0] == '/'){
                    href = href.substring(1);
                } 
                href = href.ReplaceAll('/','-');
                if (location.pathname.contains('/countries/view/') ){
                     var exp = new RegExp('/countries/view/id/\\d*');
                     var curl = exp.exec(location.pathname)
                     el.set('href',curl+'/pr/'+href);
                }
            }
        }
        home = $$('.sitereview_main_create_listtype_'+listingId);
        el = $(home[0]);
        if (el !== null){
            href = el.get('href');
            if (!href.contains('/countries/view/')){
                el.set('href',href+'/cid/'+country_id+'/format/smoothbox');
                el.addClass('smoothbox');
                Smoothbox.bind();
            }
        }
        
        //hide not support 
        home = $$('.sitereview_main_browse_location_listtype_'+listingId);
        home.setStyle('display','none');
        home = $$('.sitereview_main_common_categories');
        home.setStyle('display','none');
        
        var meneumore = $$('.layout_sitereview_navigation_sitereview');
        home = $(meneumore[0]);
        home = home.getElement('.more_tab');
        if (home != null){
            home.setStyle('display','none');
        }
        
        return;  
        
        var container = $$('.layout_sitereview_navigation_sitereview .sr_navigation_common');
        container = $(container[0]);
        var els = container.getElements('a');
        for (var j = 0; j < els.length; j ++){
            var el = $(els[j]);
            var href = el.get('href');
            var elHref = href;
            
            if (href.contains('/countries/view/')) continue;
            if (href[0] == '/'){
                href = href.substring(1);
            } 
            href = href.ReplaceAll('/','-');
            if (location.pathname.contains('/countries/view/')  && !elHref.contains('/'+listingType+'/create')){
                 var exp = new RegExp('/countries/view/id/\\d*');
                 var curl = exp.exec(location.pathname)
                 el.set('href',curl+'/pr/'+href);
            }
            
            if (elHref.contains('/'+listingType+'/create')) {
                console.log(elHref);
                el.set('href',elHref+'/cid/'+country_id);
            }
                
        }
    }
    var actionClass = {
        'menu':changeLinkMenu,
        'navigate': changeLinkNavigate
    };
    function changeLinkToCountry(){
        
        actionClass.menu.call();
        actionClass.navigate.call();
        
    }
    
    function showTagSiteReview(){
        var exp = new RegExp('/countries/view/id/\\d*');
        var curl = exp.exec(location.pathname);
        if (location.pathname.contains(curl+'/pr/')){
           var a = $$('.tab_layout_country_content');
           tabContainerSwitch(a[0], 'generic_layout_container layout_country_content');
        }
    }
    
   
        
     
    function changeLinkSmoothbox(){
            var details = $$('.sr_browse_list_info .sr_browse_list_info_header .sr_list_title a');
            for ( var i = 0; i < details.length; i++){
                var el = $(details[i]);
                el.addClass('smoothbox') ;
            }
            details = $$('.sr_browse_list_info .sr_browse_list_info_header .sr_list_title_small a');
            for ( var i = 0; i < details.length; i++){
                var el = $(details[i]);
                el.addClass('smoothbox') ;
            }
            var categories = $$('.seaocore_categories_list .sub_cat a');
            if (categories.length > 0) {
                for ( var i = 0; i < categories.length; i++){
                    var el = $(categories[i]);
                    el.addClass('smoothbox') ;
                }
            }
            
            var eltitles  = $$('.seaocore_list_wrapper .seaocore_board_list_cont .seaocore_title a');
            if (eltitles.length > 0) {
                for ( var i = 0; i < eltitles.length; i++){
                    var el = $(eltitles[i]);
                    el.addClass('smoothbox') ;
                }
            }
            var elthumns =  $$('.seaocore_list_wrapper .seaocore_board_list_thumb .seaocore_thumb a');
            if (elthumns.length > 0) {
                for ( var i = 0; i < elthumns.length; i++){
                    var el = $(elthumns[i]);
                    el.addClass('smoothbox') ;
                }
            }
            var banner = $$('.sr_browse_banner a');
            if (banner.length > 0) banner.set('target','_blank') ;
            
            var browsethumns = $$('.sitereview_thumb_view .sr_product_details a.sr_thumb');
            if (browsethumns.length > 0){
                browsethumns.addClass('smoothbox') ;
            }
            var browsetitles = $$('.sitereview_thumb_view .sr_product_details .sr_title a');
            if (browsetitles.length > 0){
                browsetitles.addClass('smoothbox') ;
            }
            
            var browsethumns = $$('.sr_grid_view  .sr_product_details a.sr_thumb');
            if (browsethumns.length > 0){
                browsethumns.addClass('smoothbox') ;
            }
            var browsetitles = $$('.sr_grid_view  .sr_product_details .sr_title a');
            if (browsetitles.length > 0){
                browsetitles.addClass('smoothbox') ;
            }
            
            var browseList = $$('.sr_browse_list .sr_browse_list_photo a');
            if (browseList.length > 0){
                browseList.addClass('smoothbox') ;
            }
            Smoothbox.bind();
    }
    
    
     window.addEvent('domready',function(){
        console.log('begin action');
        changeLinkSmoothbox();
        changeLinkToCountry();
        
         console.log('middle action');
        changeLinkBrowseView();
        setTimeout(showTagSiteReview,1000);
        
        removeFormLink();
        addCountryIdToPostNew();
         console.log('end action');
    });
    

</script>
